import { Button, Card, Descriptions, Tag } from 'antd'
import { useNavigate, useSearchParams } from 'react-router-dom'
import { useSelector } from 'react-redux'

export default function Surrender() {
  const navigate = useNavigate()
  const [searchParams] = useSearchParams()
  const fromContract = searchParams.get('fromContract')
  const { formData } = useSelector((state: any) => state.contractSlice)

  const items = formData
    ? [
        {
          key: 'contractNo',
          label: '合同编号',
          children: formData.contractNo,
        },
        {
          key: 'type',
          label: '合同类别',
          children: formData.type,
        },
        {
          key: 'name',
          label: '合同名称',
          children: formData.name,
        },
        {
          key: 'startDate',
          label: '合同开始日期',
          children: formData.startDate,
        },
        {
          key: 'endDate',
          label: '合同结束日期',
          children: formData.endDate,
        },
        {
          key: 'jia',
          label: '甲方',
          children: formData.jia,
        },
        {
          key: 'yi',
          label: '乙方',
          children: formData.yi,
        },
        {
          key: 'status',
          label: '审批状态',
          children:
            formData.status == 1 ? (
              <Tag>未审批</Tag>
            ) : formData.status == 2 ? (
              <Tag color="green">审批通过</Tag>
            ) : (
              <Tag color="red">审批拒绝</Tag>
            ),
          span: 1,
        },
      ]
    : []

  if (!fromContract) return null

  return (
    <>
      <div>
        <Button type="primary" onClick={() => navigate('/finance/contract?fromDetail=true')}>
          返回
        </Button>
        <Card className="mt">
          <Descriptions bordered items={items} />
        </Card>
      </div>
    </>
  )
}
